//
//  UIImage+BSKImageResize.m
//  MicroMemory
//
//  Created by rimi on 16/7/15.
//  Copyright © 2016年 BlueSky. All rights reserved.
//

#import "UIImage+BSKImageResize.h"

@implementation UIImage (BSKImageResize)
- (UIImage*)transformWidth:(CGFloat)width height:(CGFloat)height {
 
	CGFloat destW = width;
	CGFloat destH = height;
	CGFloat sourceW = width;
	CGFloat sourceH = height;
 
	CGImageRef imageRef = self.CGImage;
	CGContextRef bitmap = CGBitmapContextCreate(NULL,
												destW,
												destH,
												CGImageGetBitsPerComponent(imageRef),
												4*destW,
												CGImageGetColorSpace(imageRef),
												(kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
 
	CGContextDrawImage(bitmap, CGRectMake(0, 0, sourceW, sourceH), imageRef);
 
	CGImageRef ref = CGBitmapContextCreateImage(bitmap);
	UIImage *resultImage = [UIImage imageWithCGImage:ref];
	CGContextRelease(bitmap);
	CGImageRelease(ref);
 
	return resultImage;
}
@end
